package com.sky.service.impl;

import com.sky.context.BaseContext;
import com.sky.entity.AddressBook;
import com.sky.mapper.AddressBookMapper;
import com.sky.service.AddressBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class AddressBookServiceImpl implements AddressBookService {

    @Autowired
    private AddressBookMapper addressBookMapper;

    @Override
    public void add(AddressBook addressBook) {
        addressBook.setUserId(BaseContext.getCurrentId());
        addressBook.setIsDefault(0);
        addressBookMapper.insert(addressBook);
    }


    @Override
    public List<AddressBook> list(AddressBook addressBook) {
        return addressBookMapper.getByCurrentId(addressBook);

    }


    @Override
    public void setDefault(AddressBook addressBook) {
        addressBook.setIsDefault(0);
        addressBook.setUserId(BaseContext.getCurrentId());
        addressBookMapper.update(addressBook);

        addressBook.setIsDefault(1);
        addressBookMapper.setById(addressBook);
    }


    @Override
    public void setById(AddressBook addressBook) {
        addressBookMapper.setById(addressBook);
    }


    @Override
    public void deleteById(Long id) {
        addressBookMapper.deleteById(id);
    }


    @Override
    public AddressBook lietByIds(Long id) {
        AddressBook addressBook = addressBookMapper.listByIds(id);
        return addressBook;
    }
}
